package wifiunion.com.notice.presenter;

import android.content.Context;


import java.util.HashMap;

import wifiunion.com.notice.Constants;
import wifiunion.com.notice.NoticeContact;
import wifiunion.com.notice.NoticeModel;
import wifiunion.com.notice.utils.SharedPreferencesUtils;

/**
 * Created by Administrator on 2016/12/1.
 */

public class GetNoticeDevicelistPresenter implements NoticeContact.Presenter, NoticeContact.Callback {

    private NoticeContact.View mView;
    private Context mContext;
    private NoticeModel mModel;


    public GetNoticeDevicelistPresenter(Context context, NoticeContact.View view) {
        mView = view;
        mContext = context;
        mModel = new NoticeModel();
        mView.setPresenter(this);
    }

    @Override
    public void onSuccess(Object data) {
        mView.onGetDeviceListSuccess(data);
    }

    @Override
    public void onServerFailed(Object errorObj) {
        mView.onError(errorObj);
    }

    @Override
    public void onNetFailed() {
        mView.onError("网络异常");
    }

    @Override
    public void start() {
        HashMap<String, Object> params = new HashMap<>();
        params.put("Authorization", SharedPreferencesUtils.getSharedPreferences(Constants.CONFIG_AUTHTOKEN, mContext));
        mModel.loadData(Constants.HTTP_URL_GET_DEVICELOCLIST, params, this);
    }

    @Override
    public void start(HashMap<String, Object> param1s) {
        mModel.loadData(Constants.HTTP_URL_GET_NOTICEDEVICE, param1s, this);
    }


    public void getNoticeDeviceList(HashMap<String, Object> param1s,int mType) {

        if(mType ==0)
        {
            mModel.getNoticeDeviceList(Constants.HTTP_URL_GET_NOTICEDEVICE, param1s, this);
        }
        else if(mType == 1)
        {
            mModel.getNoticeDeviceList(Constants.HTTP_URL_GET_PATROLDEVICE, param1s, this);
        }
        else if(mType == 2)
        {
            mModel.getNoticeDeviceList(Constants.HTTP_URL_GET_EXPOSUREDEVICE, param1s, this);
        }

    }

}
